package com.puchi.sdkdemo

import android.app.Application
import android.content.Intent
import com.zalyyh.advertisement.pangolin.Configure
import com.zalyyh.mvvm.Mvvmlication
import com.orhanobut.logger.AndroidLogAdapter
import com.orhanobut.logger.Logger.addLogAdapter
import com.orhanobut.logger.PrettyFormatStrategy
import com.orhanobut.logger.FormatStrategy
import com.orhanobut.logger.Logger
import com.ss.android.common.applog.TeaAgent
import com.ss.android.common.applog.TeaConfigBuilder
import com.umeng.commonsdk.UMConfigure
import com.zalyyh.game.GameApplication


class App(
    application: Application, tinkerFlags: Int,
    tinkerLoadVerifyFlag: Boolean, applicationStartElapsedTime: Long,
    applicationStartMillisTime: Long, tinkerResultIntent: Intent
) : Mvvmlication(
    application, tinkerFlags, tinkerLoadVerifyFlag, applicationStartElapsedTime,
    applicationStartMillisTime, tinkerResultIntent
) {
    companion object {
        var context: Application? = null
    }

    override fun onCreate() {
        super.onCreate()
        context = application
        Configure.get().initSdk(application)
        GameApplication.get().initDotSdk(application)
        initS()
        initRangers()
        initYmSdk()
    }

    private fun initYmSdk() {
        /**
         * 注意: 即使您已经在AndroidManifest.xml中配置过appkey和channel值，也需要在App代码中调
         * 用初始化接口（如需要使用AndroidManifest.xml中配置好的appkey和channel值，
         * UMConfigure.init调用中appkey和channel参数请置为null）。
         */
        /**
         * 初始化common库
         * 参数1:上下文，不能为空
         * 参数2:【友盟+】 AppKey
         * 参数3:【友盟+】 Channel
         * 参数4:设备类型，UMConfigure.DEVICE_TYPE_PHONE为手机、UMConfigure.DEVICE_TYPE_BOX为盒子，默认为手机
         * 参数5:Push推送业务的secret
         */
        UMConfigure.init(context, "5dfc37a64ca35701600008a0", "default",  UMConfigure.DEVICE_TYPE_PHONE,"");
        // 支持在子进程中统计自定义事件
        UMConfigure.setProcessEvent(true)
    }

    private fun initRangers() {
        TeaAgent.init(TeaConfigBuilder.create(context).setAppName("ilovepopstar").setChannel("default").setAid(173274).createTeaConfig());
    }

    private fun initS() {
        val formatStrategy = PrettyFormatStrategy.newBuilder()
            .showThreadInfo(false)  // (Optional) Whether to show thread info or not. Default true
            .methodCount(0)         // (Optional) How many method line to show. Default 2
            .methodOffset(7)        // (Optional) Hides internal method calls up to offset. Default 0
            .tag("zalyyh")   // (Optional) Global tag for every log. Default PRETTY_LOGGER
            .build()

        Logger.addLogAdapter(AndroidLogAdapter(formatStrategy))
    }
}